from khl import Bot
from db.dbTools import LiteDb
import model

from api.web import make_app
from fastapi import FastAPI
import uvicorn

import threading




def createBot(db):
    bot = Bot(token="1/MTYwMjI=/A1qSu8MwCpVgevqcONW+1w==")
    #bot.command.update_prefixes(["/","."])
    model.make_dice(bot,db)
    print("启动Bot前")
    bot.run()
    print("启动Bot后")

def createApi(db):
    app =FastAPI()
    make_app(app)
    uvicorn.run(app,host='127.0.0.1',port=8080)

if __name__ == "__main__":
    db = LiteDb()
    db.openDb("kookBot.db")
    print("DB已开启")
    #_bot = threading.Thread(target=createBot,args=(db,))
    _api = threading.Thread(target=createApi,args=(db,))
    #_bot.start()
    _api.start()
    print("创建Bot前")
    #createApi(db)
    createBot(db)
    print("创建Bot后")

    db.closeDb()
    print("DB已关闭")
